netlink: add netmask for IPv4
authorDavid Härdeman <[email protected]>
Tue, 18 Nov 2025 07:55:41 +0000 (08:55 +0100)
committerÁlvaro Fernández Rojas <[email protected]>
Thu, 27 Nov 2025 07:24:02 +0000 (08:24 +0100)
Add a netmask member to struct odhcpd_ipaddr, this is mostly for
convenience.

Signed-off-by: David Härdeman <[email protected]>
Link: https://github.com/openwrt/odhcpd/pull/320
Signed-off-by: Álvaro Fernández Rojas <[email protected]>
src/netlink.c
src/odhcpd.h

index d09e3f8058a09f44387eb5cb03fae7c28f9e8a75..c07a9e4bea33435f6279213762b292ce3fa3f131 100644 (file)
@@ -571,6 +571,9 @@ static int cb_addr_valid(struct nl_msg *msg, void *arg)
        memset(&oaddrs[ctxt->ret], 0, sizeof(oaddrs[ctxt->ret]));
        oaddrs[ctxt->ret].prefix_len = ifa->ifa_prefixlen;
 
+       if (ifa->ifa_family == AF_INET)
+               oaddrs[ctxt->ret].netmask = htonl(~((1U << (32 - ifa->ifa_prefixlen)) - 1));
+
        nla_memcpy(&oaddrs[ctxt->ret].addr, nla_addr, sizeof(oaddrs[ctxt->ret].addr));
 
        if (nla[IFA_BROADCAST])
index e708f3441feb0be56eb77c1795d83888d4eff073..88135f1968cf8e5e173c8f167471b3b870e07324 100644 (file)
@@ -176,6 +176,7 @@ struct odhcpd_ipaddr {
                /* IPv4 only */
                struct {
                        struct in_addr broadcast;
+                       in_addr_t netmask;
                };
        };
 };